/*
 * @Author: hongbin
 * @Date: 2022-05-17 13:49:04
 * @LastEditors: hongbin
 * @LastEditTime: 2022-05-19 14:37:08
 * @Description: 
 */


chrome.contextMenus.create({
    title: "文字识别",
    contexts: ['all'],
    onclick: function () {
        // 向content_scripts发送消息的函数
        function sendMessageToContentScript(message, callback) {
            // eslint-disable-next-line no-undef
            chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
                // eslint-disable-next-line no-undef
                chrome.tabs.sendMessage(tabs[0].id, message, (response) => {
                    if (callback) callback(response);
                });
            });
        }

        chrome.tabs.captureVisibleTab(null, {}, function (base64) {
            /**
            * 屏幕悬挂到最上层 供截取需要的部分
            */
            sendMessageToContentScript({ type: 'get_screenshot_data', payload: base64 }, (response) => {
                console.log("response:", response);
            });
        });

    }
})  